#!/usr/bin/env python
#-*- coding:utf-8 -*-

import itertools#无穷迭代器
three, three1 = None, None

def cal():
    global three, three1
    flag = 1
    print('(24点)')
    x = int(input('请输入a：')), int(input('请输入b：')), int(input('请输入c：')), int(input('请输入d：'))
    L = list(x)              ## tuple --> list ,即 [a,b,c,d]
    while (flag == 1):
        if L[0] <= 0 or L[1] <= 0 or L[2] <= 0 or L[3] <= 0:
            print('\n输入值不全是正数，请重新输入...')
            x = int(input('请输入a：')), int(input('请输入b：')), int(input('请输入c：')), int(input('请输入d：'))
            L = list(x)
        else:
            flag = 0

    L1 = itertools.permutations(L)          ## 全排列    排列组合迭代器
    for i in L1:                            ## 下面是实现 ((a⊕b)⊕c)⊕d 的形式
        a, b, c, d = i                      ## 枚举每一种组合
        list1 = [a + b, a - b, b - a, a * b, a / b, b / a]   #a+b, a-b, b-a, a*b, a/b, b/a 的值放到list
        #list2 = [c + d, c - d, d - c, c * d, c / d, d / c]
        for result1 in list1:
            if result1 == 0:
                list2 = [result1 + c, result1 - c, c - result1, result1 * c, result1 / c]
            else:
                list2 = [result1 + c, result1 - c, c - result1, result1 * c, result1 / c, c / result1]

            for result2 in list2:
                if result2 == 0:
                    list3 = [result2 + d, result2 - d, d - result2, result2 * d, result2 / d]
                else:
                    list3 = [result2 + d, result2 - d, d - result2, result2 * d, result2 / d, d / result2]

                for result3 in list3:
                    if abs(result3 - 24) < 1e-10:   #绝对值
                        c1 = list1.index(result1)   #获取元素位置
                        c2 = list2.index(result2)
                        c3 = list3.index(result3)
                        if c1 == 2 or c1 == 5:
                            a, b = b, a
                        first = '(' + str(a) + four[c1] + str(b) + ')'
                        if c2 == 2 or c2 == 5:
                            first, c = c, first
                        second = '(' + str(first) + four[c2] + str(c) + ')'
                        if c3 == 2 or c3 == 5:
                            second, d = d, second
                        three = str(second) + four[c3] + str(d)
                        print(three + '\n')
                        break
                if abs(result3 - 24) < 1e-10:
                    break
            if abs(result3 - 24) < 1e-10:
                break
        if abs(result3 - 24) < 1e-10:
            break

    if three == None:                   ## 下面是实现 (a⊕b)⊕(c⊕d) 的形式
        L1 = itertools.permutations(L)
        for i in L1:
            a, b, c, d = i
            list1 = [a + b, a - b, a * b, a / b]
            list2 = [c + d, c - d, c * d, c / d]
            for result1 in list1:
                for result2 in list2:
                    if result2 == 0:
                        list3 = [result1 + result2, result1 - result2, result1 * result2]
                    else:
                        list3 = [result1 + result2, result1 - result2, result1 * result2, result1 / result2]
                    for result3 in list3:
                        if abs(result3 - 24) < 1e-10:   #abs 返回绝对值
                            c1 = list1.index(result1)   #获取元素位置
                            c2 = list2.index(result2)
                            c3 = list3.index(result3)
                            three1 = '(' + str(a) + four1[c1] + str(b) + ')' + four1[c3] + '(' + str(c) + \
                                     four1[c2] + str(d) + ')'
                            print(three1 + '\n')
                            break
                    if abs(result3 - 24) < 1e-10:
                        break
                if abs(result3 - 24) < 1e-10:
                    break
            if abs(result3 - 24) < 1e-10:
                break

    if three == None and three1 == None:
        print('无解...')

if __name__ == '__main__':
    four = ['+', '-', '-', '*', '/', '/']
    four1 = ['+', '-', '*', '/']
    cal()

